package com.wang.designpattern.responsibilitychain;

import com.wang.designpattern.responsibilitychain.domain.AttendanceClockDO;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

/**
 * 迟到处理类
 */
public class AmLateAttendanceHandler extends AttendanceHandler{
    public AmLateAttendanceHandler(String name) {
        super(name);
    }

    @Override
    public void processRequest(Map<String, AttendanceClockDO> clockResultDataMap, AttendanceClockDO attendanceClockDO) {

        AttendanceClockDO clockResultData = new AttendanceClockDO();

        //1、0 < “上午实际上班打卡时间” - “上午上班时间” <= 30分钟
        if (DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getAmStartTime(),
                attendanceClockDO.getAmSetStartTime()) > 0 &&
                DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getAmStartTime(),
                        attendanceClockDO.getAmSetStartTime()) <= 30) {
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.LATE.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+1);
            clockResultData.setExceptionUnit("T");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.LATE.getExceptionType(), clockResultData);
        }
        handler.processRequest(clockResultDataMap, attendanceClockDO);
    }
}
